package cdu.zzq.dao.impl;

import java.sql.*;

public class BaseDao {
    String driver = "com.mysql.cj.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/mydb?serverTimezone=Asia/Shanghai";
    String jdbcUser = "root";
    String jdbcPwd = "123456";
    protected Connection conn = null;
    protected Statement stmt = null;
    protected PreparedStatement pstmt = null;
    protected ResultSet rs = null;

    public BaseDao() {
        connet();
    }

    void connet() {
        try {

            Class.forName("com.mysql.jdbc.Driver");

            conn = DriverManager.getConnection(url, jdbcUser, jdbcPwd);
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    void close(){
        try {
            if (rs != null && !rs.isClosed()) {
                rs.close();
            }
            if (stmt != null && !stmt.isClosed()) {
                stmt.close();
            }
            if (pstmt != null && !pstmt.isClosed()) {
                pstmt.close();
            }
            if (conn != null & !conn.isClosed()) {
                conn.close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
}
